package com.ybxx.config.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;

import com.ybxx.config.model.HousingProperty;
import com.ybxx.config.service.HousingPropertyService;
import com.ybxx.core.command.QueryFilter;
import com.ybxx.core.util.UUIDGenerator;
import com.ybxx.core.web.action.BaseAction;

public class HousingPropertyAction extends BaseAction {
	@Resource
	private HousingPropertyService housingPropertyService;
	private HousingProperty housingProperty;
	private List<HousingProperty> housingPropertys;
	private String msg="succ";
	/*删除*/
	public String remove(){
		try{
			housingPropertyService.remove(housingProperty.getHpid());
		}catch(Exception ex){
			msg="住房性质删除失败";
		}finally{
			return "succ";
		}
	}
	/*加载查看时候需要展示的数据*/
	public String view(){
		if(housingProperty!=null && StringUtils.isNotEmpty(housingProperty.getHpid())){
			housingProperty=housingPropertyService.get(housingProperty.getHpid());
		}
		return "view";
	}
	public String queryPage(){
		QueryFilter filter=new QueryFilter(getRequest());
		housingPropertys=housingPropertyService.queryPage(housingProperty,filter);
		super.setRownum(filter.getPagingBean().getTotalItems());
		super.setCurrentpage(Integer.parseInt(filter.getPagingBean().getStart()+"")/Integer.parseInt(filter.getPagingBean().getPageSize()+"")+1);
		super.setPageSize(Integer.parseInt(filter.getPagingBean().getPageSize()+""));
		return "queryPage";
	}
	/*保存新增，修改信息*/
	public String save(){
		if(StringUtils.isEmpty(housingProperty.getHpid())){
			housingProperty.setHpid(UUIDGenerator.getUUID());
		}
		try{
			housingPropertyService.save(housingProperty);
		}catch(Exception ex){
			msg="住房性质保存失败.";
		}finally{
			return "succ";
		}
	}
	/*加载修改时候需要展示的数据*/
	public String load(){
		if(housingProperty!=null && StringUtils.isNotEmpty(housingProperty.getHpid())){
			housingProperty=housingPropertyService.get(housingProperty.getHpid());
		}
		return "load";
	}
	public HousingProperty getHousingProperty() {
		return housingProperty;
	}
	public void setHousingProperty(HousingProperty housingProperty) {
		this.housingProperty = housingProperty;
	}
	public List<HousingProperty> getHousingPropertys() {
		return housingPropertys;
	}
	public void setHousingPropertys(List<HousingProperty> housingPropertys) {
		this.housingPropertys = housingPropertys;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
}
